#include <bits/stdc++.h>
using namespace std;
//#define int long long
int read () {
    int s=0,f=1;
    char t=getchar();
    while ((t>'9'||t<'0')&&t!='-') t=getchar();
    if (t=='-') {
        f=-1;
        t=getchar();
    }
    while (t<='9'&&t>='0') {
        s=s*10+(t-'0');
        t=getchar();
    }
    return s*f;
}
int n,ans=INT_MAX/2;
int pl[10001],a[10001];
int check () {
    int res=0;
    pl[0]=-11451419;
    for (int i=1;i<=n;i++) {
        int c=0;
        for (int j=i-1;j>=1;j--) {
            if (pl[i]==pl[j]) {
                if (a[i]==a[j]) c=a[i];
                break;
            }
        } 
        res+=c;
    }
    return res;
}
void work (int dep) {
    if (dep>n) {
        ans=max(ans,check());
        return ;
    }
    pl[dep]=0;
    work(dep+1);
    pl[dep]=1;
    work(dep+1);
}
signed main () {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T=read();
    while (T--) {
        n=read();
        for (int i=1;i<=n;i++) {
            a[i]=read();
        }
        ans=-INT_MAX/2;
        work(1);
        cout<<ans<<'\n';
    }
    return 0;
}